{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Beginning Downloading MPNN_CNN_BindingDB Model...\n",
      "Downloading finished... Beginning to extract zip file...\n",
      "pretrained model Successfully Downloaded...\n",
      "Running locally at: http://127.0.0.1:7867/\n",
      "Running on External URL: https://12918.gradio.app\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"1000\"\n",
       "            height=\"500\"\n",
       "            src=\"http://127.0.0.1:7867/\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x1a2969dfd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(<gradio.networking.serve_files_in_background.<locals>.HTTPServer at 0x1a27632f90>,\n",
       " 'http://127.0.0.1:7867/',\n",
       " 'https://12918.gradio.app')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from DeepPurpose import utils, models\n",
    "import gradio\n",
    "\n",
    "model = models.model_pretrained(model = 'MPNN_CNN_BindingDB')\n",
    "\n",
    "def DTI_pred(drug, target):\n",
    "    X_pred = utils.data_process(X_drug = [drug], X_target = [target], y = [0],\n",
    "                                drug_encoding = 'MPNN', target_encoding = 'CNN', \n",
    "                                split_method='no_split')\n",
    "    y_pred = model.predict(X_pred)\n",
    "    return str(y_pred[0])\n",
    "\n",
    "gradio.Interface(DTI_pred, \n",
    "                 [gradio.inputs.Textbox(lines = 5, label = \"Drug SMILES\"),\n",
    "                  gradio.inputs.Textbox(lines = 5, label = \"Target Amino Acid Sequence\")], \n",
    "                 gradio.outputs.Textbox(label = \"Predicted Affinity\")).launch(share=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
